package com.example.cloudstorage;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import java.util.HashMap;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.converter.scalars.ScalarsConverterFactory;

public class MainActivity extends AppCompatActivity {
    private TextView mTvCenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mTvCenter = (TextView) findViewById(R.id.tv_center);
    }

    public void go1(View v) {
        Toast.makeText(this, "go1", Toast.LENGTH_SHORT).show();
        Retrofit retrofit=new Retrofit.Builder()
                .baseUrl("http://192.168.1.42:8080/xutils/")
                .addConverterFactory(ScalarsConverterFactory.create())
                .build();
        UserInterServes userInterServes=retrofit.create(UserInterServes.class);
//        Call<String> call=userInterServes.regUser("sdfsaasdf");
//        Call<String> call1 = userInterServes.regUser("call");
        HashMap<String,String> headers=new HashMap<>();
        headers.put("aaa","ahead");
        headers.put("bbb","bhead");
        HashMap<String,String> bodys=new HashMap<>();
        bodys.put("username","龙傲天");
        bodys.put("userpwd","666666");
        Call<String> call = userInterServes.regUser3(headers,bodys);
        call.enqueue(new Callback<String>() {
            @Override
            public void onResponse(Call<String> call, Response<String> response) {
                String body=response.body();
                mTvCenter.setText(body);
            }

            @Override
            public void onFailure(Call<String> call, Throwable t) {

            }
        });
//        HashMap<String,String> hashMap=new HashMap<>();
//        hashMap.put("aaa","龙傲天head");
//        hashMap.put("bbb","b叔");
//        hashMap.put("username","龙傲天555");
//        hashMap.put("userpwd","666666");
//        Call<String> stringCall = userInterServes.regUser1(hashMap);
//        stringCall.enqueue(new Callback<String>() {
//            @Override
//            public void onResponse(Call<String> call, Response<String> response) {
//                String body=response.body();
//                mTvCenter.setText(body);
//            }
//
//            @Override
//            public void onFailure(Call<String> call, Throwable t) {
//
//            }
//        });
        //call.execute();

    }

    public void go2(View v) {
        Retrofit retrofit=new Retrofit.Builder()
                .baseUrl("http://192.168.1.42:8080/xutils/")
                .addConverterFactory(ScalarsConverterFactory.create())
                .build();
        UserInterServes userInterServes=retrofit.create(UserInterServes.class);
//        Call<String> call=userInterServes.regUser("sdfsaasdf");
//        Call<String> call1 = userInterServes.regUser("call");
//        HashMap<String,String> headers=new HashMap<>();
//        headers.put("aaa","ahead");
//        headers.put("bbb","bhead");
        HashMap<String,String> bodys=new HashMap<>();
        bodys.put("username","龙傲天");
        bodys.put("userpwd","666666");
        Call<String> call = userInterServes.regUser1(bodys);
        call.enqueue(new Callback<String>() {
            @Override
            public void onResponse(Call<String> call, Response<String> response) {
                String body=response.body();
                mTvCenter.setText(body);
            }

            @Override
            public void onFailure(Call<String> call, Throwable t) {

            }
        });

    }

    public void go3(View v) {
        Retrofit retrofit=new Retrofit.Builder()
                .baseUrl("http://192.168.1.42:8080/xutils/")
                .addConverterFactory(ScalarsConverterFactory.create())
                .build();
        UserInterServes userInterServes=retrofit.create(UserInterServes.class);
//        Call<String> call=userInterServes.regUser("sdfsaasdf");
//        Call<String> call1 = userInterServes.regUser("call");
//        HashMap<String,String> headers=new HashMap<>();
//        headers.put("aaa","ahead");
//        headers.put("bbb","bhead");
        HashMap<String,String> bodys=new HashMap<>();
        bodys.put("username","龙傲天");
        bodys.put("userpwd","666666");
        Call<String> call = userInterServes.regUser(bodys);
        call.enqueue(new Callback<String>() {
            @Override
            public void onResponse(Call<String> call, Response<String> response) {
                String body=response.body();
                mTvCenter.setText(body);
            }

            @Override
            public void onFailure(Call<String> call, Throwable t) {

            }
        });


    }

    public void go4(View v) {
        Toast.makeText(this, "home", Toast.LENGTH_SHORT).show();
        Retrofit retrofit=new Retrofit.Builder()
                .baseUrl("http://192.168.1.43/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        HomeServes homeServes=retrofit.create(HomeServes.class);
        homeServes.requestHome().enqueue(new Callback<HomeEntity>() {
            @Override
            public void onResponse(Call<HomeEntity> call, Response<HomeEntity> response) {
                HomeEntity homeEntity = response.body();
                System.out.println(homeEntity);
            }

            @Override
            public void onFailure(Call<HomeEntity> call, Throwable t) {

            }
        });
    }
}
